import socketio
from fastapi import FastAPI
from socketio.exceptions import ConnectionRefusedError

app = FastAPI()
sio = socketio.AsyncServer(async_mode='asgi', cors_allowed_origins=[])
sio_app = socketio.ASGIApp(sio)
app.mount('/', sio_app)


@sio.event
async def connect(sid, environ):
    print("connect ", sid)
    print("environ", environ)
    # raise ConnectionRefusedError('authentication failed')


@sio.event
async def disconnect(sid):
    print('disconnect ', sid)


@sio.on('*')
def catch_all(event, sid, data):
    print("*", sid, data)


@sio.event
async def message(sid, data):
    print('message ', data)
    return "OK", 123  ##




# pipenv run uvicorn test:app --host 0.0.0.0 --reload
